/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.telsoft.hms.lib.security.lang;


/**
 * @author HùngPV thanbotbeo10@gmail.com, hungpv@telsoft.com.vn Ngày tạo:
 * 01/08/2014
 */
public abstract class AbstractThread implements Runnable {

    volatile java.lang.Thread blinker;
    java.lang.Thread thisThread = null;
    //<editor-fold desc="@Override">

    public void start() {
        blinker = new java.lang.Thread(this);
        blinker.start();
    }

    public synchronized boolean isThreadRunning() {
        if (thisThread == null) {
            return false;
        }
        return blinker == thisThread;
    }

    @SuppressWarnings("deprecation")
	public void stop() {
        if (blinker != null) {
            try {
                blinker.stop();
            } finally {
                blinker = null;
            }
        }
    }

    @Override
    /*Không được gọi hàm này, hãy gọi start();*/
    public void run() {
        thisThread = java.lang.Thread.currentThread();
        _doSomething();
    }
    //</editor-fold>

    protected void _doSomething() {
        doWork();
    }

    public abstract void doWork();
}
